package warthog.scangen;

import java.util.*;

public class CharClass {
	static class Range {
		int lo, hi;
		Range(int lo, int hi) { this.lo = lo; this.hi = hi+1; }
		public boolean claims(int c) { return lo <= c && c < hi; }
	}
	private ArrayList<Range> foo = new ArrayList<Range>();
	boolean sense;
	public CharClass(boolean sense) {
		this.sense = sense;
	}
	public boolean has(int c) {
		for (Range r:foo) if (r.claims(c)) return sense;
		return !sense;
	}
	public void addRange(int lo, int hi) {
		foo.add(new Range(lo, hi));
	}
	public List<Character> bounds() {
		ArrayList<Character> bar = new ArrayList<Character>(2*foo.size());
		for (Range r:foo) {
			bar.add((char)r.lo);
			bar.add((char)r.hi);
		}
		return bar;
	}
	public void addPoint(int c) { addRange(c, c); }
}
